import { Globals } from './../../../shared/global';
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';

@Component({
  selector: 'ree-create',
  templateUrl: './create.component.html',
  styleUrls: ['./create.component.scss'],
})
export class CreateComponent implements OnInit {

  companyAd:string;
  companyName:string;
  userName:string;
  accountType: string;
  nzDisabled: boolean = false;

  validateForm: FormGroup;

  constructor(
    private fb: FormBuilder,
    private globals: Globals,
    private route: ActivatedRoute,
    private router: Router,
  ) { }

  setUserName(){
      this.userName=this.validateForm.controls['companyName'].value
  }

  ngOnInit() {
    console.log(sessionStorage)
    this.companyName="test";
    this.companyAd="testAd";
    //this.companyName = sessionStorage.create_companyName
    //this.companyAd = sessionStorage.create_companyAd;
    this.route.params.subscribe(
      params => {
        console.log(params['item']);
        this.accountType = params['item'];
      }
    );
    this.validateForm = this.fb.group({
      email: [null, [Validators.email]],
      companyName: [this.companyName, [Validators.required]],
      companyAd: [this.companyAd, [Validators.required]],
      userName: this.userName,
      password: "123456",
    });
  }

  getFormControl(name) {
    return this.validateForm.controls[name];
  }

  _submitForm() {
    for (const i in this.validateForm.controls) {
      console.log(i,this.validateForm.controls[i])
      this.validateForm.controls[i].markAsDirty();
    }
  }

  ngOnDestroy() {
    this.globals.paths.path.pop();
    sessionStorage.removeItem("create_companyName")
    sessionStorage.removeItem("create_companyAd")
  }

}
